/*
 * Copyright (c) Created by T C L on 2019.7.10.
 */

package cn.mumzone.pos.presenter;

import android.content.Context;

import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.util.PatternUtils;
import cn.mumzone.basic.util.ToastUtil;
import cn.mumzone.pos.model.MemberEntity;
import cn.mumzone.pos.model.source.MemberRepository;
import cn.mumzone.pos.presenter.contract.TimesCardPurchaseContract;

public class TimesCardPurchasePresenter implements TimesCardPurchaseContract.Presenter {

    private TimesCardPurchaseContract.View view;

    private Context context;

    private MemberRepository memberRepository;

    public TimesCardPurchasePresenter(Context context, TimesCardPurchaseContract.View view) {
        this.context = context;
        this.view = view;
        memberRepository = new MemberRepository();
    }

    @Override
    public void searchMember(String phone) {
        if (!PatternUtils.isMobileNO(phone)) {
            ToastUtil.makeText(context, "手机号格式不正确", false);
            return;
        }
        ToastUtil.makeText(context, "请稍后...", false);
        memberRepository.getMemberInfoByPhone(phone, new ApiCallBack<MemberEntity>() {
            @Override
            public void onSuccess(MemberEntity memberEntity) {
                view.showSearchMemberSuccess(memberEntity.getPhone());
            }

            @Override
            public void onError(BaseResponse response) {
                ToastUtil.makeText(context, response.getMsg(), false);
            }
        });
    }
}
